import { useSystemStore } from '@/stores/system';
import { onReady } from '@dcloudio/uni-app';
import { rpxTopx } from '@/utils/tools';

const usePageHeight = () => {
  const screenHeight = ref();

  const getPageHeight = () => {
    const useSystem = useSystemStore();
    const systemInfo = useSystem.getSystemInfo;
    console.log(systemInfo,'systemInfo');
    if (systemInfo) {
      screenHeight.value = systemInfo.windowHeight + 50 - rpxTopx(100) - getClientHeight();
    } else {
      useSystem.setSystemInfo(uni.getSystemInfoSync());
      screenHeight.value = uni.getSystemInfoSync().windowHeight + 50 - rpxTopx(100) - getClientHeight();
      console.log(screenHeight.value);
    }
  };
  
// 获取可视区域高度[兼容]
const getClientHeight = () => {
  const useSystem = useSystemStore();
  const systemInfo = useSystem.getSystemInfo;
  const system = systemInfo.platform;
  if(system === 'ios'){
      return 44
      // return 44 + systemInfo.statusBarHeight;
  }else if(system === 'android'){
      return 48;
      // return 48 + systemInfo.statusBarHeight;
  }else{
      return 0;
  }
}

  onReady(async() => {
    await nextTick()
    getPageHeight();
  });

  return {
    screenHeight: screenHeight,
  };
};

export default usePageHeight;
